home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1998 August: Tool Chest / Dev.CD Aug 98 TC.toast / Tool Chest / Testing & Debugging / Mac OS Development Toolkit / Automation Essentials 2.3.0 / Host Automation Folder / LaunchQuit Engine / AutoDialogAIQ New < prev    next >
Encoding:
Text File  |  1998-03-19  |  8.5 KB  |  272 lines  |  [TEXT/MPS ]

  1. #########################################################################
  2. #########################################################################
  3. ##                     Copyright © Apple Computer, Inc. 1993-1997
  4. ##                                All rights reserved
  5. #########################################################################
  6. #########################################################################
  7. #    
  8. #    Library:        AutoDialogAIQ New
  9. #    
  10. #    Version:        2.1.4
  11. #    Description:
  12. #        Contains two tasks from KTA that select menu items ending 
  13. #        in "...", then dismiss the dialogs that appear as a result.
  14. #    Contains:
  15. #        DialogButtonDismisser()
  16. #        AutoDialog()
  17. #    
  18. #    History:
  19. #        Date:        By:        Changes:
  20. #        07/23/93    KTA        Created
  21. #        08/05/95    SBR        Added Apple Copyright header for Radar 1273925
  22. #        09/27/96    BRL        Added SPEC Exception handling
  23. #        01/30/97    SBR        Deleted older exception code and comments.
  24. #        01/30/97    SBR        Added an explicit script object.
  25. #    
  26. #########################################################################
  27. #########################################################################
  28.  
  29. Libraries 
  30.     # SPEC libraries
  31.     "Globals.Lib", 
  32.     "UserInterface.Lib", 
  33.     "OutPut.Lib", 
  34.     "Misc.Lib",
  35.     "ExceptionHandling.lib";
  36.  
  37.  
  38. script AutoDialogScript()
  39. begin
  40.     AutoDialog();
  41. end;
  42.  
  43.  
  44. ########################################################################
  45. #                    DialogButtonDismisser()
  46. #=======================================================================
  47. # Author:        KTA
  48. # Description:    This routine will attempt to dismiss dialogs.  This routine was 
  49. #                created to handle several types of dialogs that are handled in other
  50. #                library routines. (1) Dialogs with title bars. (2) dialogs that 
  51. #                Do not contain 'Cancel' or 'OK' buttons.
  52. # Parameters:    windOrd:  the ordinality of the window to dismiss
  53. # Returns:        nada
  54. #=======================================================================
  55. # History:
  56. #        07/27/93    KTA        Created
  57. #        09/27/96    BRL        Added SPEC Exception handling
  58. ########################################################################
  59. Task DialogButtonDismisser(windOrd := 1)
  60. begin
  61.     dialogWind := FindWindow([window o:windOrd (*c:False*)]!);
  62.     if not(dialogWind)
  63.         dialogWind := FindWindow([window o:windOrd s:Dialog]!);
  64.     while (dialogWind)    # DoubleCheck to insure no dialog exists
  65.     begin
  66.         SpecialKey(EscapeKey, "Escape Key"); # try cancelling through Escape key if available
  67.         newFrontWindow := findWindow(dialogWind);
  68.         newFrontWindowRect := newFrontWindow.r;
  69.         if((newFrontWindow) and (newFrontWindowRect = dialogWind.rect)) # window still exists at identical position
  70.         begin
  71.  
  72.             if (_MatchBoolean([button t:'Cancel'], true))
  73.                 selectButton('Cancel');
  74.             else if (_MatchBoolean([button t:'Done'], true))
  75.                 selectButton('Done');
  76.             else if (_MatchBoolean([button t:'OK'], true))
  77.                 selectButton('OK');
  78.             else if (_MatchBoolean([button t:'No'], true))
  79.                 selectButton('No');
  80.             else if (_MatchBoolean([button t:'Yes'], true))
  81.                 selectButton('Yes');
  82.             else
  83.             begin
  84.                 SpecialKey(ReturnKey, "Return Key"); # try Okaying through Return key if available
  85.                 
  86.                 try
  87.                     newFrontWindow := match[window o:windOrd r:?newFrontWindowRect]!;
  88.                 catch theError
  89.                 begin
  90.                     if theError<>-1105
  91.                         ExceptionDispatcher(theError,,{"Match 1 in DialogButtonDismisser", {windOrd}});
  92.                         
  93.                     newFrontWindow :=[];
  94.                 end;
  95.                 
  96.                 if((newFrontWindow) and (newFrontWindowRect = dialogWind.rect)) # window still exists at identical position
  97.                 begin
  98.                     CenterofRectClick(); # try Dismissing by clicking in the center of the screen
  99.                     
  100.                     try
  101.                         newFrontWindow := match[window o:windOrd r:?newFrontWindowRect]!;
  102.                     catch theError
  103.                     begin
  104.                         if theError<>-1105
  105.                             ExceptionDispatcher(theError,,{"Match 2 in DialogButtonDismisser", {windOrd}});
  106.                             
  107.                         newFrontWindow :=[];
  108.                     end;
  109.                     
  110.                     if((newFrontWindow) and (newFrontWindowRect = dialogWind.rect)) # window still exists at identical position
  111.                     begin
  112.                         availableButtons := _Collect([button e:True w:1], true);
  113.                         
  114.                         if( availableButtons )
  115.                         begin
  116.                             #pick a button randomly
  117.                             #thisButton := AvailableButtons[random(1, card AvailableButtons)];
  118.                             #pick button 2    (standard Cancel)
  119.                             thisButton := AvailableButtons[2];
  120.                             buttonTitle := thisButton.t;
  121.                                                         
  122.                             _Select([Button t:buttonTitle]);
  123.                             LogStr("Selected the button titled '{buttonTitle}'");
  124.                             
  125.                             try
  126.                                 newFrontWindow := match[window o:windOrd r:?newFrontWindowRect]!;
  127.                             catch theError
  128.                             begin
  129.                                 if theError<>-1105
  130.                                     ExceptionDispatcher(theError,,{"Match 3 in DialogButtonDismisser", {windOrd}});
  131.                                     
  132.                                 newFrontWindow :=[];
  133.                             end;
  134.                             
  135.                             if((newFrontWindow) and (newFrontWindowRect = dialogWind.rect)) # window still exists at identical position
  136.                             begin
  137.                                 # pick button 1    (standard OK)
  138.                                 thisButton := AvailableButtons[1];
  139.                                 buttonTitle := thisButton.t;
  140.                                 
  141.                                 _Select([Button t:buttonTitle]);
  142.                                 LogStr("Selected the button titled '{buttonTitle}'");
  143.                                 
  144.                             end;
  145.                         end;
  146.                         
  147.                         try
  148.                             newFrontWindow := match[window o:windOrd r:?newFrontWindowRect]!;
  149.                         catch theError
  150.                         begin
  151.                             if theError<>-1105
  152.                                 ExceptionDispatcher(theError,,{"Match 4 in DialogButtonDismisser", {windOrd}});
  153.                                 
  154.                             newFrontWindow :=[];
  155.                         end;
  156.                         
  157.                         if((newFrontWindow) and (newFrontWindowRect = dialogWind.rect)) # window still exists at identical position
  158.                         begin
  159.                             
  160.                             _Close([window o:windOrd c:true], true);
  161.                             LogStr("Selected the close box");
  162.                         end;
  163.                         else
  164.                         # Give up if no buttons that VU can see
  165.                         begin
  166.                             LogStr("Unable to get rid of frontmost dialog, Aborting…");
  167.                             #Exit;
  168.                             return 0;
  169.                         end; #else
  170.                     end;
  171.                 end;
  172.             end;    #if
  173.         end;
  174.         wait(2);
  175.         dialogWind := findWindow(dialogWind);
  176.     end;
  177. end;
  178.  
  179. ########################################################################
  180. #                    AutoDialog(specifiedMenu)
  181. #=======================================================================
  182. # Author:        KTA
  183. # Description:    This routine will match menuItems that end in '…' or '...'.
  184. #                This should indicate that the menuitem will bring up a dialog 
  185. #                When selected. 
  186. #                Currently the dialog will be dismissed after it appears.
  187. # Parameters:    specifiedMenu - 'String' - Menu to test 
  188. #                Note: Default is to do all menus.
  189. # Returns:        nada
  190. #=======================================================================
  191. # History:
  192. #         07/27/93    KTA        Created
  193. #        09/27/96    BRL        Added SPEC Exception handling
  194. ########################################################################
  195. Task AutoDialog(specifiedMenu := '')
  196. begin
  197.     global gWindListBegin;
  198.     
  199.     InitGlobals();
  200.     
  201.     gWindListBegin := {};
  202.     
  203.     tempWindList := _Collect([window]);
  204.     
  205.     for each tempWind in tempWindList
  206.         gWindListBegin := gWindListBegin + {[window t:tempWind.t r:tempWind.r]};
  207.     
  208.  
  209.     if(specifiedMenu)    
  210.     begin
  211.         ### Collect all menuItems in menu <specifiedMenu> that end in '…' or '...'
  212.         DialogMenuItemList := _Collect([menuitem t:/≈.../ e:true m:[menu t:specifiedMenu]]) +
  213.                               _Collect([menuitem t:/≈…/ e:true m:[menu t:specifiedMenu]]);
  214.     end;
  215.     else
  216.     begin
  217.         ### Collect all menuItems that end in '…' or '...'
  218.         DialogMenuItemList := _Collect([menuitem t:/≈.../ e:true ]) +
  219.                               _Collect([menuitem t:/≈…/ e:true ]);
  220.     end;
  221.     
  222.     
  223.     ### Select the menuItems <Do the IVY Thang> and dismiss the dialogs
  224.     println "============ Starting AutoDialog Testing =============";
  225.     println; println;
  226.     for each DialogMenuItem in DialogMenuItemList
  227.     begin
  228.         if (DialogMenuItem.e and not ((*DialogMenuItem.o = 1 and*) DialogMenuItem.m.o = 1))
  229.         begin
  230.             ### Select the menuitem that will bring up a dialog
  231.             
  232.             _Select(DialogMenuItem, true);
  233.             
  234.             wait(2);
  235.             
  236.             windListNow := {};
  237.             
  238.             tempWindList := _Collect([window]);
  239.             
  240.             for each tempWind in tempWindList
  241.                 windListNow := windListNow + {[window t:tempWind.t r:tempWind.r]};
  242.             
  243.             x := card windListNow;         # x = how ever many windows there are
  244.  
  245.             for i := 1 to x begin
  246.                 currentWind := windListNow[i];  # currentWind := first item in list of windows up now
  247.  
  248.                 if not isMember(currentWind, gWindListBegin) begin ## not working
  249.                     theNewWindow := currentWind;
  250.                     i := x + 1;
  251.                 end;
  252.  
  253.             end;
  254.             
  255.             theNewWindow := _Match(theNewWindow);
  256.                 
  257.             theMenuTitle := DialogMenuItem.t;
  258.             LogStr( "-------- Selected the menuitem - '{theMenuTitle}' - it should bring up a dialog ------");
  259.             
  260.             if (global gIVYHook)
  261.                 Call (gIVYHook);
  262.                 
  263.             ### Dismiss the dialog
  264.             wait(2);            # Give Dialog time to appear
  265.             #if not(DialogHandler())
  266.                 DialogButtonDismisser(theNewWindow.o);
  267.             println;
  268.         end;
  269.     end;
  270. end;
  271.  
  272.